/*
-----------------------------------------------------------------------------
This source file is part of FRAPPER
research.animationsinstitut.de
sourceforge.net/projects/frapper

Copyright (c) 2008-2009 Filmakademie Baden-Wuerttemberg, Institute of Animation 

This program is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the Free Software
Foundation; version 2.1 of the License.

This program is distributed in the hope that it will be useful, but WITHOUT
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public License along with
this program; if not, write to the Free Software Foundation, Inc., 59 Temple
Place - Suite 330, Boston, MA 02111-1307, USA, or go to
http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
-----------------------------------------------------------------------------
*/

 //!
//! \file "ViewNode.h"
//! \brief Header file for ViewNode class.
//!
//! \author     Stefan Habel <stefan.habel@filmakademie.de>
//! \author     Nils Zweiling <nils.zweiling@filmakademie.de>
//! \version    0.7
//! \date       20.02.2009 (last updated)
//!

#ifndef VIEWNODE_H
#define VIEWNODE_H

#include "CurveEditorDataNode.h"
#include <Ogre.h>
#if (OGRE_PLATFORM  == OGRE_PLATFORM_WIN32)
#include <windows.h>
#endif

Q_DECLARE_METATYPE(Ogre::SceneNode *)
//!
//! Abstract base class for all nodes whose results can be viewed in a
//! viewport.
//!
//! ViewNodes can either produce 3D scene geometry or 2D images (/textures).
//!
class FRAPPER_CORE_EXPORT ViewNode : public CurveEditorDataNode
{

    Q_OBJECT

public:

    //!
    //! Constructor of the ViewNode class.
    //!
    //! \param name The name for the new node.
    //! \param parameterRoot A copy of the parameter tree specific for the type of the node.
    //!
    ViewNode ( const QString &name, ParameterGroup *parameterRoot );

    //!
    //! Destructor of the ViewNode class.
    //!
    //! Defined virtual to guarantee that the destructor of a derived class
    //! will be called if the instance of the derived class is saved in a
    //! variable of its parent class type.
    //!
    virtual ~ViewNode ();

public: // functions

    //!
    //! Returns the index of the stage in which this node is contained.
    //!
    //! \return The index of the stage in which this node is contained.
    //!
    unsigned int getStageIndex () const;

    //!
    //! Returns whether the result of this node should be displayed in the
    //! viewport.
    //!
    //! \return True if the result of this node should be displayed in the viewport, otherwise False.
    //!
    bool isViewed () const;

    //!
    //! Returns the scene node that contains scene objects created or modified
    //! by this node.
    //!
    //! The default implementation returns 0.
    //! To be implemented in derived classes that work on scene geometry data.
    //!
    //! \return The scene node containing objects created or modified by this node.
    //!
    virtual Ogre::SceneNode * getSceneNode ();

    //!
    //! Returns the image that is generated by this node.
    //!
    //! The default implementation returns an empty texture pointer.
    //! To be implemented in derived classes that work on image data.
    //!
    //! \return The image that is generated by this node.
    //!
    virtual Ogre::TexturePtr getImage ();

public slots: //

    //!
    //! Sets whether this node should be evaluated in the network.
    //!
    //! \param evaluate The new value for eval flag of this node.
    //!
    virtual void setEvaluate ( bool evaluate );

    //!
    //! Sets whether the geometry of this node should be displayed in the
    //! viewport.
    //!
    //! \param view The new value for view flag of this node.
    //! \param suppressViewSetSignal Flag to control whether the viewSet signal is emitted from this function.
    //!
    virtual void setView ( bool view, bool suppressViewSetSignal = false );

    //!
    //! Sets the index of the stage in which this node should be contained.
    //!
    //! \param stageIndex The index of the stage in which this node should be contained.
    //!
    void setStageIndex ( unsigned int stageIndex );

signals: //

	//!
    //! Trigger redraw of ogre scene.
    //!
	void triggerRedraw ();

    //!
    //! Signal that is emitted when the view flag of this node has been set.
    //!
    //! \param stageIndex The index of the stage to display the node in.
    //! \param viewNode This node.
    //!
    void viewSet ( unsigned int stageIndex, ViewNode *viewNode );

    //!
    //! Signal that is emitted when the currently viewed view node has been
    //! updated.
    //!
    void viewNodeUpdated ();

protected: // functions

    //!
    //! Adds the given parameter as output parameter to this view node.
    //!
    //! The viewNodeUpdated signal will be emitted when the given parameter is
    //! made dirty.
    //!
    //! \param outputParameter The parameter that when dirtied will trigger the viewNodeUpdated signal.
    //!
    void addOutputParameter ( Parameter *outputParameter );
	
	//!
    //! Request a redraw of the current ogre scene. 
    //!
	void requestRedraw ();

private slots: //

    //!
    //! Checks if the view flag is currently set for this node and if so
    //! notifies connected objects that the view node has been updated by
    //! emitting the viewNodeUpdated signal.
    //!
    void checkViewFlag ();

protected: // data

    //!
    //! The index of the stage in which this node is contained.
    //!
    unsigned int m_stageIndex;

    //!
    //! Flag that states whether the result of this node should be displayed in
    //! the viewport.
    //!
    bool m_view;

};


#endif
